package cn.tedu.util;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.tedu.vo.Result;

/**
 * 这是一个相应工具类
 * @author Administrator
 *
 */
public class ResponseUtil {
	/**
	 * 此方法是把json数据响应到客户端
	 * @param response
	 * @param result
	 * @throws IOException
	 */
	public static void jsonToClient(HttpServletResponse response,Result result) throws IOException {
		response.setContentType("text/html;charset=utf-8");
		String resultJson=JSON.toJSONString(result);
		System.out.println(resultJson);
		PrintWriter out=response.getWriter();
		out.println(resultJson);
		out.flush();
		out.close();
	}
	/**
	 * 把字符串文本响应到客户端
	 * @param response
	 * @param message
	 * @throws IOException
	 */
	public static void messageToClient(HttpServletResponse response,String message) throws IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		out.println(message);
		out.flush();
		out.close();
	}
}
